<template>
  <view class="card-page">
    <view class="header">
      {{sayHello}}，{{userInfo.name||'test'}}
    </view>
    <image class="notice" src="../../../static/images/bg-header/view_notice.png" @click="toNotice"></image>
    
    <view class="items">
      <view class="item tcard" v-for="item in list" :key="item.id" v-show="item.service != '1'">
        <view class="title">
          {{ item.companyName }}
        </view>
        
        <view class="tform no-border">
          <view class="tform-item">
            <view class="label">
              体检人
            </view>
            <view class="value">
              {{userInfo.name}}
            </view>
          </view>
          <view class="tform-item">
            <view class="label">
              体检套餐
            </view>
            <view class="value">
              {{item.pkgName}}
            </view>
          </view>
          <view class="tform-item">
            <view class="label">
              有效时间
            </view>
            <view class="value">
              {{item.reserveTime.substr(0, 4) + '-' + item.reserveTime.substr(4, 2) + '-' + item.reserveTime.substr(6, 2)}}
            </view>
          </view>
        </view>
        <view style="padding: 0 12upx;">
          <view class="bottom">
            <view class="status" :style="{color: item.status ? 'rgba(0,0,0,0.24)' : '#5DD2B1'}">
              {{ item.checkStatus != 0 ? '已使用' : '未使用'}}
            </view>
            <view v-if="item.checkStatus == 0" class="btn light" @click="toDetail(item)">
              去预约
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
	var dayjs = require('dayjs')
	import { mapGetters } from 'vuex';
  import {getPreferentialList} from '@/api/physical.js'
	import { getQuestion, poQuestion } from '@/api/otherService.js'
  export default {
    data() {
      return {
        list: []
      }
    },
    computed:{
    	...mapGetters(['userInfo', 'systemParams', 'userList']),
      sayHello() {
        let setTime = dayjs(new Date()).format("H");
        if (setTime >= 0 && setTime < 6) {
      	return "凌晨好";
        } else if (setTime >= 6 && setTime < 11) {
      	return "早上好";
        } else if (setTime >= 11 && setTime < 14) {
      	return "中午好";
        } else if (setTime >= 14 && setTime < 19) {
      	return "下午好";
        } else {
      	return "晚上好";
        }
      }
    },
    onLoad() {
      if (!this.userInfo.userId) return uni.navigateTo({
        url: '/pages/Login/addPatient'
      })
      
      this.initData()
      this.getPreferentialList()
    },
    methods: {
      initData(){
      	let info = {
      		type:2,
      		patientId:this.userInfo.patId
      	}
      	getQuestion(info).then(data => {
      		data = data[0]
      		let question = {
      			title : data.title||'',
      			subtitle : data.subtitle||'',
      			paperId:data.paperId||'',
      			status:data.whetherCompleted==='0'?true:false
      		}
          if (question.status) return
          uni.navigateTo({
            url: '/pages/tabBar/Questionnaire/Index'
          })
      	}).catch(e => {
      	})
      },
      getPreferentialList() {
        const data = {
          identityCard: this.userInfo.idCard
        }
        getPreferentialList(data).then(res => {
          this.list = Array.isArray(res) ? res : [res]
        })
      },
      toNotice() {
        uni.navigateTo({
          url: `../PhysicalNotice/PhysicalNotice`,
        })
      },
      toDetail(item) {
        uni.navigateTo({
          url: `../PackageDetail/PackageDetail?pkg=${JSON.stringify(item)}`,
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
.card-page {
  background-image: url(../../../static/images/bg-header/page_bk2.png);
  display: flex;
  flex-direction: column;
}
.header {
  font-family: PingFang SC, PingFang SC;
  font-weight: 600;
  font-size: 28upx;
  color: #FFFFFF;
  line-height: 44upx;
  padding-left: 16upx;
  margin-bottom: 18upx;
}
.notice {
  width: 230upx;
  height: 40upx;
  margin-left: 16upx;
  margin-bottom: 26upx;
}
.items {
  flex: 1;
  overflow: auto;
  .item {
    // padding: 32upx;
    .tform-item {
      padding: 12upx;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid rgba(0,0,0,0.12);
      padding-top: 20upx;
      .btn {
        width: 122upx;
        height: 42upx;
        background: $theme-color;
        border-radius: 42upx;
        text-align: center;
        line-height: 42upx;
        color: #FFF;
        font-size: 24upx;
      }
      .light {
        background: transparent;
        border: 1px solid $theme-color;
        color: $theme-color;
      }
    }
  }
}
</style>
